package com.bruan.create_thread;

public class ThreadTest2_2 {
    public static void main(String[] args) throws InterruptedException {
        //1. 直接创建Runnable匿名内部类形式
        Runnable target = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("子线程1 输出==》"+i);
                    try {
                        Thread.sleep(10); // 添加延迟
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        new Thread(target).start();
        //简化形式1
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("子线程2 输出==》"+i);
                    try {
                        Thread.sleep(10); // 添加延迟
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }).start();

        //简化形式2
        new Thread(() -> {
                for (int i = 0; i < 100; i++) {
                    System.out.println("子线程2 输出==》"+i);
                    try {
                        Thread.sleep(10); // 添加延迟
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        ).start();

        for (int i = 0; i < 100; i++) {
            System.out.println("主线程输出");
            Thread.sleep(100); // 添加延迟
        }

    }
}
